// Angular Version 6 below need to be deleted {providedIn: 'root'}

// angular
import {Injectable} from '@angular/core';
import {HttpParams} from '@angular/common/http';
// owner
import {Request} from 'pengesoft-ng-lib';
// models
import {Salary} from '../domains/salary.domain';
import {SalaryDto} from '../domains/salarydto.domain';
// import {any[]} from '../domains/any[].domain';

/**
 * SalaryMgeSvr
 */
@Injectable({
  providedIn: 'root'
})
export class SalaryMgeSvr {
  baseUrl: string;

  constructor(
    private request: Request
  ){
    this.baseUrl = 'SalaryMgeSvr.assx/';
  }

  /**
   * 
   */
  getSalaryDtoByEmpId(empId: string): Promise<SalaryDto>{
    const httpParams = new HttpParams()
      .append('empId', empId.toString());
    return this.request.post<SalaryDto>(this.baseUrl + 'getSalaryDtoByEmpId', httpParams).then((res) => {
      return new SalaryDto(res);
    });
  }

  /**
   * 
   */
  addSalary(salary: Salary): Promise<number>{
    const httpParams = new HttpParams()
      .append('salary', salary.toString());
    return this.request.post<number>(this.baseUrl + 'addSalary', httpParams).then((res) => {
      return res;
    });
  }

  /**
   * 
   */
  GetVersion(): Promise<string>{
    const httpParams = new HttpParams();
    return this.request.post<string>(this.baseUrl + 'GetVersion', httpParams).then((res) => {
      return res;
    });
  }

  /**
   * 
   */
  getDetailListByEmpId(empId: string): Promise<any[]>{
    const httpParams = new HttpParams()
      .append('empId', empId.toString());
    return this.request.post<any[]>(this.baseUrl + 'getDetailListByEmpId', httpParams).then((res) => {
      return res;
    });
  }

  /**
   * 
   */
  getDetailByEmpId(empId: string): Promise<Salary>{
    const httpParams = new HttpParams()
      .append('empId', empId.toString());
    return this.request.post<Salary>(this.baseUrl + 'getDetailByEmpId', httpParams).then((res) => {
      return new Salary(res);
    });
  }

  /**
   * 
   */
  addSalaryRecord(empId: string, oldSalary: number, nowSalary: number, changeReason: string): Promise<number>{
    const httpParams = new HttpParams()
      .append('empId', empId.toString())
      .append('oldSalary', oldSalary.toString())
      .append('nowSalary', nowSalary.toString())
      .append('changeReason', changeReason.toString());
    return this.request.post<number>(this.baseUrl + 'addSalaryRecord', httpParams).then((res) => {
      return res;
    });
  }
}
